<?php


class EventsResultSet
{
	private $events=array();
	private $from; // DateTime object
	private $to; // DateTime object
	
	private $sql="";
	
	public function __construct()
	{
	$this->from = new DateTime("now"); // DateTime object
	$this->to = new DateTime("now"); // DateTime object
	}
	
	public function setFrom($from){$this->from=$from;}
	public function setTo($to){$this->to=$to;}
	
	public function setSql($sql){$this->sql =$sql;}
	
	
	
	public function getEvents()
	{
		$database=$GLOBALS['DATABASE']->Recopy();
		
		if ($this->sql=="")
		{
			$sql="SELECT EventID FROM Events WHERE Events.Start>='".$this->from->format("Y-m-d");
			$sql.="' AND Events.Start<'".$this->to->format("Y-m-d");
			$sql.="' AND Events.DeletedBy=0 ";
			$sql.=" ORDER BY Events.Start";
		}
		else $sql=$this->sql;
		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$event=new Event($row['EventID']);
//			echo $row['Title'];
			array_push($this->events,$event);
		}
		return $this->events;
	}
}
